/***************************************************************************
 *   Copyright (C) 2008 by mj   *
 *   hanfman_cool@web.de   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

//steamserverutil is a program to manage the steam game servers from hldsupdatetool.bin
//v0.2.4.3, last changes: 28.08.08 20:49



//#ifdef HAVE_CONFIG_H
//#include <config.h>
//#endif
//#include <cstdlib>

#include <iostream> //for cout and cin
#include <fstream> //for ifstream and ofstream
#include <stdlib.h> //for system()
#include <string.h> //for strcpy, strcat and strcmp

//to make the differance of the arrays better 
#define OFF_N 0
#define OFF_C 1


using namespace std;


//global variables
char param[500];	//here are the params from function choice_params() saved and the path of the server for mani admin plugin

//to test if server is currently installed (is set true when server is installed)
bool server_css, server_dods, server_garrysmod, server_hl2mp, server_tf, server_cs, server_czero, server_dmc, server_dod, server_gearbox, server_ricochet, server_tfc, server_darkmessiah;

bool installed=false; //is set true when server is installed

//functions
void not_installed() {cout << "\n\nServer not installed!";}
void never_happen()  {cout << "\n\nOops steamserverutil crashed!! Please make a bug report to hanfman_cool@web.de";}

//tests which server are installed
void is_installed()
{
	cout << "\n\nServers available: \n\n";
	

	//testing if games are installed
	ifstream test_reg;
	test_reg.open("server_css/InstallRecord.blob");

	if(test_reg.is_open())
	{
		cout << "1.  Counter Strike Source\n";
		server_css = true;
	}
	test_reg.close();

	test_reg.open("server_dods/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "2.  Day of Defeat Source\n";
		server_dods=true;
	}
	test_reg.close();
	
	test_reg.open("server_garrysmod/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "4.  Garrys Mod\n";
		server_garrysmod = true;
	}
	test_reg.close();
	
	test_reg.open("server_hl2mp/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "5.  Half Life 2 Deathmatch\n";
		server_hl2mp=true;
	}
	test_reg.close();
	
	test_reg.open("server_tf/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "6.  Team Fortress\n";
		server_tf = true;
	}
	test_reg.close();
	
	test_reg.open("server_cs/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "7.  Counter Strike\n";
		server_cs=true;
	}
	test_reg.close();
	
	test_reg.open("server_czero/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "8.  Counter Strike Condition Zero\n";
		server_czero = true;
	}
	test_reg.close();
	
	test_reg.open("server_dmc/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "9.  Deathmatch Classic\n";
		server_dmc=true;
	}
	test_reg.close();
	
	test_reg.open("server_dod/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "10. Day of Defeat\n";
		server_dod = true;
	}
	test_reg.close();
	
	test_reg.open("server_gearbox/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "11. Opposing Force\n";
		server_gearbox=true;
	}
	test_reg.close();
	
	test_reg.open("server_ricochet/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "12. Ricochet\n";
		server_ricochet = true;
	}
	test_reg.close();
	
	test_reg.open("server_tfc/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "13. Team Fortress Classic\n";
		server_tfc=true;
	}
	test_reg.close();
	
	test_reg.open("server_darkmessiah/InstallRecord.blob");
	if(test_reg.is_open())
	{
		cout << "15. Dark Messiah\n";
		server_darkmessiah=true;
	}
	test_reg.close();
}


//function which tests if the server is really installed, if it is installed it saves the path in the char param[]
void mani_test(unsigned short int choice)
{
	switch(choice)
	{
		case 1:	if(server_css==true)
			{
						
				strcpy(param, "server_css/cstrike");
				installed = true;
			}
			else
			not_installed();
			break;
		case 2:	if(server_dods==true)
			{
				strcpy(param, "server_dods/orangebox/dod");
											
				
				installed = true;
			}
			else
			not_installed();
			break;
		case 4:	if(server_garrysmod==true)
			{
					cout << "\nNot supported!";
			}
			else
			not_installed();
			break;
		case 5:	if(server_hl2mp==true)
			{
				strcpy(param, "server_hl2mp/hl2mp");
						
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 6:	if(server_tf==true)
			{	
				strcpy(param, "server_tf/orangebox/tf");
					
				installed = true;
			}
			else
			not_installed();
			break;
		case 7:	if(server_cs==true)
			{
			cout << "\nNote that this server is not officially supported by mani admin plugin";


				strcpy(param, "server_cs/cstrike");
									
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 8:	if(server_czero==true)
			{
		
			cout << "\nNote that this server is not officially supported by mani admin plugin";


			strcpy(param, "server_czero/czero");
							
									
				
			installed = true;
			}
			else
			not_installed();
			break;
		case 9:	if(server_dmc==true)
			{
					cout << "\nNot supported!";
			}
			else
			not_installed();
			break;
		case 10:	if(server_dod==true)
				{
					cout << "\nNote that this server is not officially supported by mani admin plugin";

					strcpy(param, "server_dod/dod");
								
					
					installed = true;
				}
				else
				not_installed();
				break;
		case 11:	if(server_gearbox==true)
				{
					cout << "\nNot supported!";
				}
				else
				not_installed();
				break;
		case 12:	if(server_ricochet==true)
				{
					cout << "\nNot supported!";
				}
				else
				not_installed();
				break;
		case 13:	if(server_tfc==true)
				{
					cout << "\nNot supported!";
				}
				else
				not_installed();
				break;
		case 14:	if(server_darkmessiah==true)
				{

					cout << "\nNot supported!";
			
				}
				else
				not_installed();
				break;
		default: cout << "\n\nTry again ;)\n\n";
			break;
	}
}


//installs servers
void install()
{
	bool exit=false;
	
	while(!exit)
	{
		unsigned short int choice;
		
		cout << "\n\nServers available for install: \n";
		cout << "1.  Counter Strike Source\n";
		cout << "2.  Day of Defeat Source\n";
		cout << "3.  Day of Defeat Source Beta (no longer supported, please install manually)\n";
		cout << "4.  Garrys Mod\n";
		cout << "5.  Half Life 2 Deathmatch\n";
		cout << "6.  Team Fortress\n";
		cout << "7.  Counter Strike\n";
		cout << "8.  Counter Strike Condition Zero\n";
		cout << "9.  Death Match Classic\n";
		cout << "10. Day of Defeat\n";
		cout << "11. Opposing Force\n";
		cout << "12. Ricochet\n";
		cout << "13. Team Fortress Classic\n";
		cout << "14. Dark Messiah\n";
		cout << "15. EXIT to main menu\n";
		cout << " : ";
		cin >> choice;
		cin.ignore();
		
		switch(choice)
		{
			case 1: 	cout << "\n\nInstalling Counter Strike-Source Server...\nCreating directory...\n\n";
					system("mkdir server_css");
					system("./steam -command update -game \"Counter-Strike Source\" -dir server_css");
					break;
			case 2: 	cout << "\n\nInstalling Day of Defeat Source Server...\nCreating directory...\n\n";
					system("mkdir server_dods");
					system("./steam -command update -game \"dods\" -dir server_dods");
					break;
			case 4: 	cout << "\n\nInstalling Garrys Mod Server...\nCreating directory...\n\n";
					system("mkdir server_garrysmod");
					system("./steam -command update -game \"garrysmod\" -dir server_garrysmod");
					break;
			case 5: 	cout << "\n\nInstalling Half Life 2 Deathmatch Server...\nCreating directory...\n\n";
					system("mkdir server_hl2mp");
					system("./steam -command update -game \"hl2mp\" -dir server_hl2mp");
					break;
			case 6: 	cout << "\n\nInstalling Team Fortress Server...\nCreating directory...\n\n";
					system("mkdir server_tf");
					system("./steam -command update -game \"tf\" -dir server_tf");
					break;
			case 7: 	cout << "\n\nInstalling Counter Strike Server...\nCreating directory...\n\n";
					system("mkdir server_cs");
					system("./steam -command update -game \"cstrike\" -dir server_cs");
					break;
			case 8: 	cout << "\n\nInstalling Counter Strike Condition Zero Server...\nCreating directory...\n\n";
					system("mkdir server_czero");
					system("./steam -command update -game \"czero\" -dir server_czero");
					break;
			case 9: 	cout << "\n\nInstalling Death Match Classic Server...\nCreating directory...\n\n";
					system("mkdir server_dmc");
					system("./steam -command update -game \"dmc\" -dir server_dmc");
					break;
			case 10: 	cout << "\n\nInstalling Day of Defeat Server...\nCreating directory...\n\n";
					system("mkdir server_dod");
					system("./steam -command update -game \"dod\" -dir server_dod");
					break;
			case 11: 	cout << "\n\nInstalling Opposing Force Server...\nCreating directory...\n\n";
					system("mkdir server_gearbox");
					system("./steam -command update -game \"gearbox\" -dir server_gearbox");
					break;
			case 12: 	cout << "\n\nInstalling Ricochet Server...\nCreating directory...\n\n";
					system("mkdir server_ricochet");
					system("./steam -command update -game \"ricochet\" -dir server_ricochet");
					break;
			case 13: 	cout << "\n\nInstalling Team fortress Classic Server...\nCreating directory...\n\n";
					system("mkdir server_tfc");
					system("./steam -command update -game \"tfc\" -dir server_tfc");
					break;
			case 14: 	cout << "\n\nInstalling Dark Messiah Server...\nCreating directory...\n\n";
					system("mkdir server_darkmessiah");
					system("./steam -command update -game \"darkmessiah\" -dir server_darkmessiah");
					break;
			case 15: 	exit=true;
					break;
			default: 	cout << "\n\nTry again;)\n\n";
					break;
		}
		
	}
	
}


//adjustements for server
void param_choice()
{

	char temp[200];
	char choice;


	param[0] = 0; //0 means end of string, to avoid errors with strcat()


	cout << "\n\nDisable Valve Anti Cheat System?(y|n) ";
	cin >> choice;

	cin.ignore();

	
	if(choice == 'y')
	{
		strcat(param, "-insecure ");
	}
	
	cout <<"\n\nDisable bots?(y|n) ";
	cin >> choice;

	cin.ignore();

	if(choice == 'y')
	{
		strcat(param, "-nobots ");
	}
	
	cout << "\n\nSpecify IP?(y|n) ";
	cin >> choice;

	cin.ignore();

	if(choice == 'y')
	{
		cout <<"\n\nIP: ";
		cin.getline(temp, 100);
//		cin.ignore();

		strcat(param, "-ip ");
		strcat(param, temp);
		strcat(param, " ");
	}

	
	
	cout << "\n\nSpecify port?(y|n) ";
	cin >> choice;
	cin.ignore();

	if( choice=='y')
	{
		cout <<"\n\nPort: ";
		cin.getline(temp, 100);

		strcat(param, "-port ");
		strcat(param, temp);
		strcat(param, " ");	
	}

//	cin.ignore();

	
	cout << "\n\nMaximal Players? ";
	cin.getline(temp, 200);

	
	strcat(param, "+maxplayers ");
	strcat(param, temp);
	strcat(param, " ");

//	cin.ignore();


	cout << "\n\nWhich map? ";
	cin.getline(temp, 200);


	strcat(param, "+map ");
	strcat(param, temp);
	strcat(param, " ");

//	cin.ignore();


	cout << "\n\nOnly Lan Server?(y|n) ";
	cin >> choice;

	cin.ignore();
	
	
	if(choice=='y')
	{
		strcat(param, "+sv_lan 1 ");
	}
	
	cout << "\n\nSpecify hostname?(y|n) ";
	cin >> choice;

	cin.ignore();
	

	if (choice == 'y')
	{
		cout << "\n\nHostname: ";
		cin.getline(temp, 100);
		strcat(param, "+hostname ");
		strcat(param, temp);
	}

//	cin.ignore();
	
	cout << "\n\nstart server as a new process(independent of this)?(y|n) ";
	char neww;
	cin >> neww;
	
	if(neww== 'y')
		strcat(param, "&>server_output.log"); //to start as a new process
	
	

}


//here you can start a server
void start()
{

	char params[(strlen("cd server_css && ./srcds_run ") + 500)];
		


	bool _installed = false;


	cout << "\n\nWhich server should be started?\n\n";
	is_installed();
	unsigned short int choice;
	cout << " : ";
	cin >> choice;
	cin.ignore();

	switch(choice)
	{
		case 1:	if(server_css==true)
				{
					
					
					_installed = true;
					
					strcpy(params, "cd server_css && ./srcds_run -game cstrike ");

				}
				else
				not_installed();
				break;
		case 2:	if(server_dods==true)
				{
					_installed = true;
					strcpy(params, "cd server_dods/orangebox && ./srcds_run -game dod ");
				
		
			
			
				
					
				}
				else
				not_installed();
				break;

		case 4:	if(server_garrysmod==true)
				{
					_installed = true;
					strcpy(params, "cd server_garrysmod && ./srcds_run ");
				

	
			
					
				}
				else
				not_installed();
				break;
		case 5:	if(server_hl2mp==true)
				{
					_installed = true;
					strcpy(params, "cd server_hl2mp && ./srcds_run -game hl2mp ");
				

	
				
					
				}
				else
				not_installed();
				break;
		case 6:	if(server_tf==true)
				{	
					_installed = true;
					strcpy(params, "cd server_tf && ./srcds_run ");


				}
				else
				not_installed();
				break;
		case 7:	if(server_cs==true)
				{
					_installed = true;
					strcpy(params, "cd server_cs && ./srcds_run -game cstrike ");
			

				

			
					
				}
				else
				not_installed();
				break;
		case 8:	if(server_czero==true)
				{
					_installed = true;
					strcpy(params, "cd server_czero && ./srcds_run -game czero ");
			

			

			
					
				}
				else
				not_installed();
				break;
		case 9:	if(server_dmc==true)
				{
					_installed = true;
					strcpy(params, "cd server_dmc && ./srcds_run ");
					

				
				
					
				}
				else
				not_installed();
				break;
		case 10:	if(server_dod==true)
				{
					_installed = true;
					strcpy(params, "cd server_dod && ./srcds_run ");
				

			
		
					
				}
				else
				not_installed();
				break;
		case 11:	if(server_gearbox==true)
				{
					_installed = true;
					strcpy(params, "cd server_gearbox && ./srcds_run ");
				

			
			
				
			
				
				}
				else
				not_installed();
				break;
		case 12:	if(server_ricochet==true)
				{
					_installed = true;

					strcpy(params, "cd server_ricochet && ./srcds_run ");
			

			
		
			
			
				}
				else
				not_installed();
				break;
		case 13:	if(server_tfc==true)
				{
					_installed = true;
					strcpy(params, "cd server_tfc && ./srcds_run ");
					

			
					
			
				}
				else
				not_installed();
				break;
		case 14:	if(server_darkmessiah==true)
				{
					_installed = true;

					strcpy(params, "cd server_darkmessiah && ./srcds_run ");
					

				
					
			
			
				}
				else
				not_installed();
				break;
		default: cout << "\n\nTry again ;)\n\n";
				break;
	}
	
	if( _installed == true)
	{	
		param_choice();
		strcat(params, param);
		
		
	
		//here the server starts
	
		cout << "\nStarting the server...";
		
		cout << flush; //the message should come before the server starts ;)
		
		system(params);
	}
}


//here you can adjust and start your favorites


void favorites()
{

	char input[100][2][550];


	int j;
	
	

	
	bool exit = false;
	unsigned short int choice;
	
	//read .favorites and save entrys in variables
	while(!exit)
	{


		j=-1;	

		ifstream in;
		in.open(".favorites");
		cout << "\n\nReading favorites...\n\n";
	
		if(in.is_open())
		{

			char temp[550];
				
	

	
			while(!in.eof())
			{
	
				
				
				in.getline(temp, 550);
	
				switch(temp[0])
				{
					case 'n': if(temp[1] == ':')
						  {
							j++;
							strcpy(input[j][OFF_N], &(temp[3]));
							
						  }
						 else
						 cout << "Your .favorites is incorrupt, cannot understand: " << temp << "\nIgnoring...\n";
						break;
					case 'c': if(temp[1] == ':')
						  {
							strcpy(input[j][OFF_C], &(temp[3]));
						  }
						 else
						 cout << "Your .favorites is incorrupt, cannot understand: " << temp << "\nIgnoring...\n";
						 break;
					default: if(temp[0] == 10 || temp[0]== 0) //10 means new line 0 means end of string
						 {
							//nothing to do
						 }
						 else
						 cout << "Your .favorites is incorrupt, cannot understand: " << temp << "\nIgnoring...\n";
						break;
				}
				
				if(j > 100)
				{
					never_happen();
					cout << "\nToo many favorites (>100)\n";
					break;
				}
			}
	
			
			
		}
		else
		{
			cout << "You have no favorites, please add one!\n\n";
		}
	
		in.close();
		







		//reading is finished, now user can adjust favorites
		unsigned short int choice;
		char params[(sizeof("cd server_tshb && ./srcds_run ") + 500)];
		char name[100];
		
		bool installed = false; //is set true when server is installed

		ofstream save;
		save.open(".favorites", ios_base::app);
		
		cout << "\n\n1. Add favorite\n";
		cout << "2. Delete favorite\n";
		cout << "3. Delte all favorites\n";
		cout << "4. Start favorite\n";
		cout << "5. Back to main menu\n";
		cout << " : ";
		cin >> choice;

		

		switch(choice)
		{
			

			case 1: cout << "\n\nFrom which game should be the favorite?\n\n";


				is_installed();

				unsigned short int choice;
				cout << " : ";
				cin >> choice;
				cin.ignore();

				switch(choice)
				{
						case 1:	if(server_css==true)
								{
					
									strcpy(params, "cd server_css && ./srcds_run -game cstrike ");
									installed = true;
								}
								else
								not_installed();
								break;
						case 2:	if(server_dods==true)
								{
									strcpy(params, "cd server_dods/orangebox && ./srcds_run -game dod ");
																
					
									installed = true;
								}
								else
								not_installed();
								break;
						case 4:	if(server_garrysmod==true)
								{
									strcpy(params, "cd server_garrysmod && ./srcds_run ");
									
					
									installed = true;
								}
								else
								not_installed();
								break;
						case 5:	if(server_hl2mp==true)
								{
									strcpy(params, "cd server_hl2mp && ./srcds_run -game hl2mp ");
									
									
									installed = true;
								}
								else
								not_installed();
								break;
						case 6:	if(server_tf==true)
								{	
									strcpy(params, "cd server_tf && ./srcds_run ");
									
									installed = true;
								}
								else
								not_installed();
								break;
						case 7:	if(server_cs==true)
								{
									strcpy(params, "cd server_cs && ./srcds_run -game cstrike ");
									
									
									installed = true;
								}
								else
								not_installed();
								break;
						case 8:	if(server_czero==true)
								{
									strcpy(params, "cd server_czero && ./srcds_run -game czero ");
									
									
									installed = true;
								}
								else
								not_installed();
								break;
						case 9:	if(server_dmc==true)
								{
									strcpy(params, "cd server_dmc && ./srcds_run ");
									
					
									installed = true;
								}
								else
								not_installed();
								break;
						case 10:	if(server_dod==true)
								{
									strcpy(params, "cd server_dod && ./srcds_run ");
									
					
									installed = true;
								}
								else
								not_installed();
								break;
						case 11:	if(server_gearbox==true)
								{
									strcpy(params, "cd server_gearbox && ./srcds_run ");
									
			
									installed = true;
				
								}
								else
								not_installed();
								break;
						case 12:	if(server_ricochet==true)
								{

									strcpy(params, "cd server_ricochet && ./srcds_run ");
									
							
									installed = true;
								}
								else
								not_installed();
								break;
						case 13:	if(server_tfc==true)
								{
									strcpy(params, "cd server_tfc && ./srcds_run ");
									
			
									installed = true;
								}
								else
								not_installed();
								break;
						
						case 14:	if(server_darkmessiah==true)
								{

									strcpy(params, "cd server_darkmessiah && ./srcds_run ");
									
									installed = true;
			
								}
								else
								not_installed();
								break;
						default: cout << "\n\nTry again ;)\n\n";
							break;
					}
					

					

					if(installed==true)
					{
						cout << "\n\nNow you should make a few adjustments for the favorite\n\n";
	
						param_choice();

						strcat(params, param);
					
						cout << "\n\nWhich name do you wish for this favorite? ";
						cin.getline(name, 100);

						//cin.ignore();

						save << "n: " << name << endl;
						save << "c: " << params << endl;
						save.close();
					}

					break;


			case 2: cout << "\n\nWhich favorite server do you want to delete?\n\n";
				for (int i = 0; i<=j;i++)
				{
					cout << (i+1) << "\t" <<  input[i][OFF_N] << endl;
				}
				
				cout << " : ";
				cin >> choice;
				
				choice--;


				if(choice > j)
				{
					cout << "\n\nThis entry does not exist!";
				}
				else
				{

					ofstream save_del;
					save_del.open(".favorites");




					for (int i = 0;i<=j;i++)
					{

						
						if(i==choice)
						{
							//nothing to do
						}
						else
						{
							save_del << "n: " << input[i][OFF_N] << endl;
							save_del << "c: " << input[i][OFF_C] << endl;
						}
							
					}
					save_del.close();
				}
				break;

			case 3: char temp;
				cout << "\n\nAll favorites are going to be deleted. Are you sure?(y|n) ";
				cin >> temp;
				

				if(temp=='y')
				{
					ofstream del_all;
					del_all.open(".favorites");
					del_all.close();
				}
				break;
			case 4: cout << "\n\nWhich favorite server do you want to start?\n\n";
				for (int i = 0; i<=j;i++)
				{
					cout << (i+1) << "\t" <<  input[i][OFF_N] << endl;
				}
				
				cout << " : ";
				cin >> choice;

				choice--;
				
				if(choice > j)
				{
					cout << "\n\nThis entry does not exist!";
					break;
				}
				else
				{	
					cout << "\n\nStarting favorite...";	
					
					cout << flush; //the message should come before the server starts ;)
		
					system(input[choice][OFF_C]);
				}
				break;
			case 5: exit=true;
				break;
			default: cout << "\n\nTry again ;)\n";
		} 
		

	save.close();
	
	}
	
}

void copy_maps()
{
	
	char params[550]; //here is saved the complete cp command
	
	cout << "\n\nInto which server do you want to copy the maps?";

	is_installed();

	

	unsigned short int choice;
	cout << " : ";
	cin >> choice;
	cin.ignore();

	bool installed=false; //is set true when server is installed


	

	switch(choice)
	{
		case 1:	if(server_css==true)
			{
						
				strcpy(params, "cd server_css/cstrike && ");
				installed = true;
			}
			else
			not_installed();
			break;
		case 2:	if(server_dods==true)
			{
				strcpy(params, "cd server_dods/orangebox/dod && ");
											
				
				installed = true;
			}
			else
			not_installed();
			break;
		case 4:	if(server_garrysmod==true)
			{
				strcpy(params, "cd server_garrysmod/orangebox && ");
									
					
				installed = true;
			}
			else
			not_installed();
			break;
		case 5:	if(server_hl2mp==true)
			{
				strcpy(params, "cd server_hl2mp/hl2mp && ");
						
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 6:	if(server_tf==true)
			{	
				strcpy(params, "cd server_tf/orangebox/tf && ");
					
				installed = true;
			}
			else
			not_installed();
			break;
		case 7:	if(server_cs==true)
			{
				strcpy(params, "cd server_cs/cstrike && ");
									
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 8:	if(server_czero==true)
			{
				strcpy(params, "cd server_czero/czero && ");
							
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 9:	if(server_dmc==true)
			{
				strcpy(params, "cd server_dmc/dmc && ");
				
						
				installed = true;
			}
			else
			not_installed();
			break;
		case 10:	if(server_dod==true)
				{
					strcpy(params, "cd server_dod/dod && ");
								
					
					installed = true;
				}
				else
				not_installed();
				break;
		case 11:	if(server_gearbox==true)
				{
					strcpy(params, "cd server_gearbox/gearbox && ");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 12:	if(server_ricochet==true)
				{
					strcpy(params, "cd server_ricochet/ricochet && ");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 13:	if(server_tfc==true)
				{
					strcpy(params, "cd server_tfc/tfc && ");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 14:	if(server_darkmessiah==true)
				{

					strcpy(params, "cd server_darkmessiah && ");
									
					installed = true;
			
				}
				else
				not_installed();
				break;
		default: cout << "\n\nTry again ;)\n\n";
			break;
	}
					

					

	if(installed==true)
	{
		char temp[530];
		
		cout << "\n\nWhere are the maps? ";
		cin.getline(temp, 500);

		strcat(params, "cp -v ");
		strcat(params, temp);
		strcat(params, "/* maps/ ");

		system(params);
		
		//cin.ignore();

		
	}
	
}

void edit_mapcl(int x)
{
	//x=1 to edit maplist.txt
	//x=2 to edit mapcycle.txt
	//x=3 to edit votemaplist.txt (only with mani admin plugin)



	char params[60];

	cout << "\n\nFrom which server do you want to edit the ";
	if(x==1)
	cout << "maplist?";
	if(x==2)
	cout << "mapcycle?";
	if(x==3)
	cout << "votemaplist.txt?";


	is_installed();

	

	unsigned short int choice;
	cout << " : ";
	cin >> choice;
	cin.ignore();

	bool installed=false; //is set true when server is installed


	

	switch(choice)
	{
		case 1:	if(server_css==true)
			{
						
				strcpy(params, "server_css/cstrike");
				installed = true;
			}
			else
			not_installed();
			break;
		case 2:	if(server_dods==true)
			{
				strcpy(params, "server_dods/orangebox/dod");
											
				
				installed = true;
			}
			else
			not_installed();
			break;
		case 4:	if(server_garrysmod==true)
			{
				strcpy(params, "server_garrysmod/orangebox");
									
					
				installed = true;
			}
			else
			not_installed();
			break;
		case 5:	if(server_hl2mp==true)
			{
				strcpy(params, "server_hl2mp/hl2mp");
						
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 6:	if(server_tf==true)
			{	
				strcpy(params, "server_tf/orangebox/tf");
					
				installed = true;
			}
			else
			not_installed();
			break;
		case 7:	if(server_cs==true)
			{
				strcpy(params, "server_cs/cstrike");
									
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 8:	if(server_czero==true)
			{
				strcpy(params, "server_czero/czero");
							
									
				installed = true;
			}
			else
			not_installed();
			break;
		case 9:	if(server_dmc==true)
			{
				strcpy(params, "server_dmc/dmc");
				
						
				installed = true;
			}
			else
			not_installed();
			break;
		case 10:	if(server_dod==true)
				{
					strcpy(params, "server_dod/dod");
								
					
					installed = true;
				}
				else
				not_installed();
				break;
		case 11:	if(server_gearbox==true)
				{
					strcpy(params, "server_gearbox/gearbox");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 12:	if(server_ricochet==true)
				{
					strcpy(params, "server_ricochet/ricochet");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 13:	if(server_tfc==true)
				{
					strcpy(params, "server_tfc/tfc");
									
			
					installed = true;
				}
				else
				not_installed();
				break;
		case 14:	if(server_darkmessiah==true)
				{

					strcpy(params, "server_darkmessiah");
									
					installed = true;
			
				}
				else
				not_installed();
				break;
		default: cout << "\n\nTry again ;)\n\n";
			break;
	}




	if(installed==true)
	{

		char mapfolder[70];


		
		strcpy(mapfolder, params);
		strcat(mapfolder, "/maps/");

		if (x==1)
		{
			strcat(params, "/maplist.txt");
	
		}
		if(x==2)
		{
			strcat(params, "/mapcycle.txt");
	
		}
		if(x==3)
		{
			strcat(params, "/cfg/mani_admin_plugin/votemaplist.txt");
		}







		bool exit =false;
			
		while(!exit)
		{
	
			if((x !=1) && (x !=2) && x !=3)
			{
				never_happen();
				break;
			}


			if (x==1)
			{
				cout << "\n\nHere is your current maplist: \n\n";
			}
			if(x==2)
			{
		
				cout << "\n\nHere is your current mapcycle: \n\n";
			}
			if(x==3)
			{
				cout << "\n\nHere is your current votemaplist: \n\n";
			}



	
			//x=1 to edit maplist.txt
			//x=2 to edit mapcycle.txt
			//x=3 to edit votemaplist.txt (only with mani admin plugin)

		
			
	
			ifstream input; //to read current *.txt
			input.open(params);

			ofstream output; //to add a new entry
			output.open(params, ios_base::app);


			char maps[350][50];
			unsigned int i;

			i=0;

			if(input.is_open())
			{	
				while(!input.eof())
				{
			
				
					input.getline(maps[i], 50);

					if(maps[i][0] == 10 || maps[i][0] == 0) //10 means new line, 0 means end of string
					{
						//nothing to do
					}
					else
					{
						cout << (i+1) << ".\t" << maps[i] << endl;
						i++;
					}
				}
			}
			else
			{
				cout << "\nNo maps. Please add one\n";
			
			}	
			input.close();





		
			unsigned short int choice;
			
			cout << "\n\n1. Add a map\n";
			cout << "2. Delete a map\n";
			cout << "3. Copy all maps from map folder\n";
			cout << "4. Delete all maps\n";
			cout << "5. Back \n";
			cout << " : ";

			cin >> choice;

			cin.ignore();


			

			char temp[50];
	
			switch(choice)
			{
				case 1: cout << "\n\nName of map? ";
					cin.getline(temp, 50);

					output << endl << temp;
					break;

				case 2: cout << "\n\nWhich map do you wish to delete? ";
					unsigned int choice;

					cin >> choice;
					choice--;
					
					if (choice >= i)
					{
						cout << "\n\nThis entry does not exist!\n";
					}
					else
					{
						ofstream save_del;
						save_del.open(params);

						for (int y = 0; y<i; y++)
						{
							if(y==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << maps[y] << endl;
							}
						}
						save_del.close();
					}
					break;

				case 3: 
					char map[100];

					map[0]='^'; // to avoid errors with strncmp()
					map[1]=0;

					strcpy(temp, "ls -1 ");
					strcat(temp, mapfolder);
					strcat(temp, " > temp.txt");

					system(temp);

					
					{
						ifstream in_temp;
						in_temp.open("temp.txt");

						ofstream out;
						out.open(params);
						
						if(in_temp.is_open())
						{
							while(!in_temp.eof())
							{
								char temp[100];
								
								in_temp.getline(temp, 200);


								if(!strncmp(temp, map, strlen(map)))
								{
									continue;
								}

								if(!strcmp(temp, "materials"))
								{
									continue;
								}
					
								if(!strcmp(temp, "graphs"))
								{
									continue;
								}

								if(!strcmp(temp, "soundcache"))
								{
									continue;
								}



								for(int i=0; i <= strlen(temp); i++)
								{
									int k = 0;
									switch(temp[i])
									{
										case '.': k=1; 
											  break;
										default: map[i]=temp[i];
											break;
									}
									if(k==1)
									{
										map[i]=0; //0 means end of string
										break;
									}
								}
								out << map << endl;
							}
						}
						else
						{
							never_happen();
							cout << "Cannot open temp.txt";
						}

						in_temp.close();
						out.close();
					}


					
					system("rm -rf temp.txt");

					break;

					
				case 4: char tempi;
					cout << "\n\nAll the maps are going to be deleted. Are you sure?(y|n) ";
					cin >> tempi;
				

					if(tempi=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 5: exit=true;
					
					break;
				
				default: cout << "\n\nWrong choice. Try again ;)";
					 break;
			}


			
			output.close(); //closing file to add a new entry
			
		}
	



	}



}

void install_mani()
{
	cout << "\n\nIn which server do you want to install mani admin plugin?\n\n";

	unsigned int choice;

	is_installed();

	cout << "\n : ";

	char params[300]; //the hole command is saved here

	cin >> choice;
	cin.ignore();



	strcpy (params, "cd "); //because in function mani_test the "cd " is not included

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcat(params, param);
	//-------end---------(modified)


	if(installed==true)
	{
		if (choice==6)
		{
			
			cout << endl << endl << "Downloading mani admin plugin with wget, unzipping archive..." << endl << endl;
			strcat (params, " && wget -N http://www.mani-admin-plugin.com/mani_admin_plugin/v1_2_beta_s/mani_admin_plugin_v1_2_beta_s_orange.zip && ");

			//to download mani admin plugin


			strcat(params, "unzip -o mani_admin_plugin_v1_2_beta_s_orange.zip ");
			//to unzip mani amdin plugin (unzips automatically in right folder)

			system(params);
		}
		else
		{
			cout << endl << endl << "Downloading mani admin plugin with wget, unzipping archive..." << endl << endl;
			strcat (params, " && wget -N http://www.mani-admin-plugin.com/mani_admin_plugin/v1_2_beta_s/mani_admin_plugin_v1_2_beta_s.zip && ");

			//to download mani admin plugin



			strcat(params, "unzip -o mani_admin_plugin_v1_2_beta_s.zip ");
			//to unzip mani amdin plugin (unzips automatically in right folder)

			system(params);

		}



		ofstream save_vdf;

		cout << "\n\nCreating mani_admin_plugin.vdf\n";

		switch (choice)
		{

			case 1: 
				save_vdf.open("server_css/cstrike/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../cstrike/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			case 2: 
				save_vdf.open("server_dods/orangebox/dod/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../dod/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			case 5: 
				save_vdf.open("server_hl2mp/hl2mp/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../hl2mp/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			case 6:
				save_vdf.open("server_tf/orangebox/tf/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../tf/addons/mani_admin_plugin\"\n";
				save_vdf << "}"; 
				break;


			case 7: 
				save_vdf.open("server_cs/cstrike/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../cstrike/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			case 8: 
				save_vdf.open("server_czero/czero/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../czero/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			case 10:
				save_vdf.open("server_dod/dod/addons/mani_admin_plugin.vdf");
				
				save_vdf << "\"Plugin\"\n";
				save_vdf << "{\n";
				save_vdf << " \"file\" \"../dod/addons/mani_admin_plugin\"\n";
				save_vdf << "}";
				break;

			default: never_happen();
				 break;

		}


		cout << "\n\nMani Admin Plugin succesfully installed!\n";
			
	}
}

void deactivate_mani()
{
	cout << "\n\nForm which server do you wish to deactivate the mani admin plugin? \n";
	
	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	
	cin >> choice;

	char params[100];


	strcpy(params, "cd "); //the "cd " is not include by mani_test(int)
	
	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcat(params, param);
	//-------end---------(modified)


	

	if(installed==true)
	{
		cout << "\n\nDeactivating mani admin plugin...\nDeleting mani_admin_plugin.vdf";
		strcat(params, " && rm -rf addons/mani_admin_plugin.vdf");


		system(params);
	}


}


void mani_admins()
{
	bool exit = false;


	char params[100];

	cout << "\n\nFrom which server do you want to manage the admins?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------

	if(installed==true)
	{

		//copy old adminlist to the new one!
		char temp[200];
		strcpy(temp, "cd ");
		strcat(temp, params);
		strcat(temp, " && ");
		strcat(temp, "cp cfg/mani_admin_plugin/adminlist.txt.old cfg/mani_admin_plugin/adminlist.txt");
		system(temp);

		strcat(params, "/cfg/mani_admin_plugin/adminlist.txt");

		cout << endl << endl;

		while (!exit)
		{


			char input[50][2][200]; //OFF_N = 0 means name; OFF_C = 1 means steam id or ip
			
			ifstream in;
			in.open(params);


			int counter = 0;

			if(in.is_open())
			{

				cout << "\n\nCurrent admins: \n";
				
				while(!in.eof())
				{
					char temp[200];

					in.getline(temp, 200);


				
					switch(temp[0])
					{
						case 'S': if(!strncmp(temp, "STEAM", 5))
							  {
								strcpy(input[counter][OFF_C], temp);
							  }
							  else
							   cout << "\n\nCannot understand: " << temp << "\nIgnoring...";

							  break;
						
						case ';': strcpy(input[counter][OFF_C], temp);
							  break;
						case '/': if(!strncmp(temp, "//n: ", 5))
							  {
								strcpy(input[counter][OFF_N], &temp[5]);
								cout << (counter+1) << ".\t" << input[counter][OFF_N] << endl;
								counter++;
							  }
							  break;
						default: 
							if(temp[0] == 10 || temp[0]== 0) //10 means new line 0 means end of string
							 {
								//nothing to do
							 }
						 	 else
						 	 cout << "\n\nCannot understand: " << temp << "\nIgnoring...";
					}
				}
			}
			else
			{
				cout << "\nNo admins. Please add one\n";
			
			}
			in.close();


			cout << "\n\n1. Add admin\n";
			cout << "2. Delete admin\n";
			cout << "3. Delte all admins\n";
			cout << "4. Exit\n";
			cout << " : ";

			cin >> choice;
			cin.ignore();


			char temp[200];

			ofstream out;
			out.open(params, ios_base::app);

			switch(choice)
			{
				case 1: 
					
					cout << "\n\nSteam ID or IP of the player? ";
					cin.getline(temp, 200);
					
					//test if steam id or ip
					if(!strncmp(temp, "STEAM", 5))
					{
						out << endl << temp << endl;
					}
					else
					{
						out << endl<< ";"<< temp << endl;
					}


					cout << "\nName or steam account of the player? ";
					cin.getline(temp, 200);
					out << "//n: " << temp;
					break;
				case 2: cout << "\n\nWhich admin do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << endl << input[i][OFF_C] ;
								save_del << "//n: " << input[i][OFF_C] << endl;
							}
							
						}
						save_del.close();
					}
					break;
				case 3: char temp;
					cout << "\n\nAll admins are going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
				

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 4: exit=true;
					break;
				default: cout << "\n\nTry again;)\n\n";
					 break;
			}

		out.close();

		}
	}
}


void mani_wordfilter()
{
	bool exit=false;

	char params[100];

	cout << "\n\nFrom which server do you want to manage the admins?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;


	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------



	if(installed==true)
	{


	strcat(params, "/cfg/mani_admin_plugin/wordfilter.txt");

	char filter[200][50];

	int counter = 0;

	while(!exit)
	{

		int counter = 0;


		ifstream in;
		in.open(params);
		
		cout << "\nhere is your wordfilter:  \n";

		if(in.is_open())
		{
			while (!in.eof())
			{
				char temp[50];

				in.getline(temp, 50);

				switch(temp[0])
				{
					case '/': //nothing to do
					  break;
					case 10: //nothing to do (10 means new line)
						 break;
					case 0: //nothing to do (0 means end of string)
						 break;
					default: strcpy(filter[counter], temp);
						 cout << (counter + 1) << "\t" << filter[counter] << endl;
						counter++; 
						break;
				}
			}
		}
		else
		cout << "\nNo wordfilters. Please add one!\n";

		cout << "\n\n1. Add word\n";
		cout << "2. Delete word\n";
		cout << "3. Delte complete wordfilter\n";
		cout << "4. Exit\n";
		cout << " : ";
		cin >> choice;
		cin.ignore();

		switch (choice)
		{
			case 1: cout << "\nWord: ";
				{
					char temp[50];
					cin.getline(temp, 50);
						ofstream out;
					out.open(params, ios_base::app);
					out << endl << temp;
					out.close();
				}
				break;


				case 2: cout << "\n\nWhich word do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << endl << filter[i];
							}
							
						}
						save_del.close();
					}
					break;
				case 3: char temp;
					cout << "\n\nThe hole wordfilter is going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
					

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 4: exit=true;
					break;
				default: cout << "\n\nTry again;)\n\n";
					 break;
			}
		}
		
	}

}

void mani_rcon()
{


	char params[200];
	bool exit = false;

	cout << "From which server do you wish to edit the rconlist?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------

	char buf[50][2][50]; //OFF_name means 0, OFF_C means 1	


	

	if(installed==true)
	{

	
		strcat(params, "/cfg/mani_admin_plugin/rconlist.txt");
		


		


		while (!exit)
		{

			unsigned short int counter = 0;

			ifstream in;
			in.open(params);

			if(in.is_open())
			{
			

				cout << "\n\nCurrent rconlist: \n";


				while(!in.eof())
				{
					char temp[100];
					in.getline(temp, 100);
				
					switch(temp[0])
					{
						case '"': int i;
						  	for(i=1; i<100; i++)
						  	{
								if(temp[i]=='"')
							  	  break;

								buf[counter][OFF_N][(i-1)] = temp[i];
							  }

							buf[counter][OFF_N][i] = 0; //0 means end of string

							  cout << (counter+1) << ".\t" << buf[counter][OFF_N] << endl;



							  i+=2; //to junp over the '"' and over the ' '

							  int j;
						  	  for(j=0; i<100; i++, j++)
							  {
								if((temp[i]=='/' && temp[(i+1)] == '/') || temp[i] == 0) //0 means end of string
								   break;

								buf[counter][OFF_C][j] = temp[i];
							  }

							  
							  buf[counter][OFF_C][j] = 0; //0 means end of string

							  counter++;
							  
							  temp[0] = 0; //0 means end of string, to avoid the bug with the letter when temp[] = "\"\" "
							  
							  break;
						
						case 10: //10 means new line
							//nothing to do
							break;
						case 0://0 means end of string
							//nothing to do
							break;
						case '/': if (temp [1] == '/')
								break;

						default: strcpy(buf[counter][OFF_N], temp);
							 strcpy(buf[counter][OFF_C], temp);
							 
							 cout << (counter+1) << ".\t" << buf[counter][OFF_N] << endl;
							 
							 counter++;
							
					}

					if(counter > 49)
					{
						never_happen();
						cout << "\nToo many commands(>50)\n";
						break;
					}
				
				}

				in.close();

			}
		
			else
			cout << "\nYou have no rcon commands, please add one!\n";

		
		

			cout << "\n\n1. Add command\n";
			cout << "2. Delete command\n";
			cout << "3. Edit a command\n";
			cout << "4. Add Surf Mod Option\n";
			cout << "5. Delete hole list\n";
			cout << "6. Exit\n";


			cout << " : ";
			cin >> choice;
			cin.ignore();


			switch(choice)
			{
				case 1: cout << "\nCommand: ";
					{
						char command[50];
						cin.getline(command, 50);

						cout << "\nName: ";
						char name[50];
						cin.getline(name, 50);

						ofstream out;
						out.open(params, ios_base::app);
						out << endl << "\"" << name << "\"" << " " << command;
						out.close();
					}
					break;

			
				case 2: cout << "\n\nWhich entry do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
									save_del << endl << "\"" << buf[i][OFF_N] << "\"" << " " << buf[i][OFF_C];
							}
							
						}
						save_del.close();
					}
					break;


				case 3:	cout << "\nWhich entry do you wish do edit? ";
					cin >> choice;
					
					choice--; //for thr right array


					if (choice >= counter)
					{
						cout << "\n\nThis entry does not exist!\n\n";
					}
					else
					{
						cout << "\n\n1. Edit the Name\n";
						cout << "2. Edit the command\n";
						cout << " : ";
						unsigned short int temp_e;
						cin >> temp_e;
						cin.ignore();

						if(temp_e > 2)
						{
							cout << "\n\nWrong choice!\n";
						}
						else
						{
							temp_e--;  //for the right array
							cout << "\nNew name/command: ";
							cin.getline(buf[choice][temp_e], 100);

	

							ofstream save_edit;
							save_edit.open(params);




							for (int i = 0;i<counter;i++)
							    save_edit  << "\"" << buf[i][OFF_N] << "\"" << " " << buf[i][OFF_C] << endl;

				
						
						}

					}

					break;

				case 4: {
						ofstream surf;
						surf.open(params, ios_base::app);

						surf << "\n\"Surf Mod On\" sv_airaccelerate 2000\n";
						surf << "\"Surf Mod Off\" sv_airaccelerate 1";
						surf.close();


					}
					cout << "\nSucces!\n";
					break;

				case 5: char temp;
					cout << "\n\nThe hole rconlist is going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
					

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 6: exit = true;
					break;
				default: cout << "\n\nTry again;)\n";
			}
		}
	}
}

		
void mani_votequestionlist()
{
	char params[200];
	bool exit = false;

	cout << "From which server do you wish to edit the votequestionlist?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------

	char buf[50][2][50]; //OFF_name means 0, OFF_C means 1	


	

	if(installed==true)
	{

	
		strcat(params, "/cfg/mani_admin_plugin/votequestionlist.txt");
		


		


		while (!exit)
		{

			unsigned short int counter = 0;

			ifstream in;
			in.open(params);

			if(in.is_open())
			{
				cout << "\n\nCurrent votequestionlist: \n";


				while(!in.eof())
				{
					char temp[100];
					in.getline(temp, 100);
				
					switch(temp[0])
					{
						case '"': int i;
						  	for(i=1; i<100; i++)
						  	{
								if(temp[i]=='"')
							  	  break;

								buf[counter][OFF_N][(i-1)] = temp[i];
							  }
							  
							  buf[counter][OFF_N][i] = 0; //0 means end of string

							  cout << (counter+1) << ".\t" << buf[counter][OFF_N] << endl;

							 

							  i+=3; //to junp over the '"' and over the ' ' and the second '"'

							  int j;
						  	  for(j=0; i<100; i++, j++)
							  {
								if(temp[i]=='"')
								   break;

								buf[counter][OFF_C][j] = temp[i];
							  }

							  
							  buf[counter][OFF_C][j] = 0; //0 means end of string

							 // cout << buf[0][OFF_C] << " "  << buf[1][OFF_C];

							  counter++;
							  
							  temp[0] = 0; //0means end of string, to avoid the bug with the letter when temp[] = "\"\" "
							  
							  break;
			

							
					}
				
				}

				in.close();
			}
		
			else
			cout << "\nYou have no votequestions, please add one!\n";






			cout << "\n\n1. Add question\n";
			cout << "2. Delete a question\n";
			cout << "3. Edit a question\n";
			cout << "4. Delete hole list\n";
			cout << "5. Exit\n";


			cout << " : ";
			cin >> choice;
			cin.ignore();


			switch(choice)
			{
				case 1: cout << "\nQuestion: ";
					{
						char question[50];
						cin.getline(question, 50);

						cout << "\nName: ";
						char name[50];
						cin.getline(name, 50);

						ofstream out;
						out.open(params, ios_base::app);
						out << endl << "\"" << name << "\"" << " \"" << question << "\"";
						out.close();
					}
					break;

			
				case 2: cout << "\n\nWhich entry do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << endl << "\"" << buf[i][OFF_N] << "\"" << " \"" << buf[i][OFF_C] << "\"";
							}
							
						}
						save_del.close();
					}
					break;


				case 3:	cout << "\nWhich entry do you wish do edit? ";
					cin >> choice;
					
					choice--; //for the right array


					if (choice < counter)
					{
						cout << "\n\nThis entry does not exist!\n\n";
					}
					else
					{
						cout << "\n\n1. Edit the Name\n";
						cout << "\n\n2. Edit the question\n";
						cout << " : ";
						unsigned short int temp_e;
						cin >> temp_e;

						if(temp_e > 2)
						{
							cout << "\n\nWrong choice!\n";
						}
						else
						{
							temp_e--;  //for the right array
							cout << "\nNew name/question: ";
							cin.getline(buf[choice][temp_e], 100);

	

							ofstream save_edit;
							save_edit.open(params);




							for (int i = 0;i<counter;i++)
							    save_edit  << "\"" << buf[i][OFF_N] << "\"" << " \"" << buf[i][OFF_C] << "\"" << endl;

				
						
						}

					}

					break;

				case 4: char temp;
					cout << "\n\nThe hole votequestionlist is going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
					

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 5: exit = true;
					break;
				default: cout << "\n\nTry again;)\n";
		
		} //switch

	}//while(!exit)




	}//if(installed=true)
}




void mani_ping_reserve(int x)
{
	bool exit = false;


	//x = 1 means reserveslots, x = 2 means pingimmunity

	char params[100];

	cout << "\n\nFrom which server do you want to manage the ";
	
	if(x==1)
	cout << "reserveslots?\n";
	else
	cout << "pingimmunity\n";
	
	
	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;


	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------


	if(installed==true)
	{

		if(x==1)
		strcat(params, "/cfg/mani_admin_plugin/reserveslots.txt");
		else
		strcat(params, "/cfg/mani_admin_plugin/pingimmunity.txt");

		cout << endl << endl;

		while (!exit)
		{


			char input[50][2][200]; //OFF_N = 0 means name; OFF_C = 1 means steam id or ip
			
			ifstream in;
			in.open(params);


			int counter = 0;

			if(in.is_open())
			{

				cout << "\n\nCurrent ";
				
				if(x==1)
				cout << "reserveslots: \n";
				else
				cout << "pingimmunities: \n";
				
				while(!in.eof())
				{
					char temp[200];

					in.getline(temp, 200);


				
					switch(temp[0])
					{
						case 'S': if(!strncmp(temp, "STEAM", 5))
							  {
								strcpy(input[counter][OFF_C], temp);
							  }
							  else
							   cout << "\n\nCannot understand: " << temp << "\nIgnoring...\n";

							  break;
						
						case '/': if(!strncmp(temp, "//n: ", 5))
							  {
								strcpy(input[counter][OFF_N], &temp[5]);
								cout << (counter+1) << ".\t" << input[counter][OFF_N] << endl;
								counter++;
							  }
							  break;
						default: 
							if(temp[0] == 10 || temp[0]== 0 || temp[0] == 13) //10 means new line 0 means end of string 13 means "\r"
							 {
								//nothing to do
							 }
						 	 else
						 	 cout << "\n\nCannot understand: " << temp << "\nIgnoring...\n";

							 break;
					}
	
					if(counter > 50)
					{
						never_happen();
						cout << "\nToo many entrys (>50)\n";
						break;
					}
				}
			}
			else
			{
				cout << "\nNo entrys. Please add one\n";
			
			}
			in.close();


			cout << "\n\n1. Add a person\n";
			cout << "2. Delete a person\n";
			cout << "3. Delte all persons\n";
			cout << "4. Exit\n";
			cout << " : ";

			cin >> choice;
			cin.ignore();


			char temp[200];

			ofstream out;
			out.open(params, ios_base::app);

			switch(choice)
			{
				case 1: 
					
					cout << "\n\nSteam ID of the player? ";
					cin.getline(temp, 200);
					
					
					out << endl << temp << endl;


					cout << "\nName or steam account of the player? ";
					cin.getline(temp, 200);
					out << "//n: " << temp;
					break;
				case 2: cout << "\n\nWhich person do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << endl << input[i][OFF_C] ;
								save_del << "//n: " << input[i][OFF_C] << endl;
							}
							
						}
						save_del.close();
					}
					break;
				case 3: char temp;
					cout << "\n\nAll persons are going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
				

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 4: exit=true;
					break;
				default: cout << "\n\nTry again;)\n\n";
					 break;
			}

		out.close();

		}
	}
}

void mani_resw()
{
	cout << "\n\nThis option is only supported by the Counter Strike Source Server\n";

	

	bool exit = false;

	while(!exit)
	{


		ifstream in;
		in.open("server_css/cstrike/cfg/mani_admin_plugin/default_weapon_restrict.txt");


		int counter = 0;
		char resw[50][15];

		cout << "\nCurrent restricted weapons: \n\n";

		if (in.is_open())
		{
			while(!in.eof())
			{
				char temp[100];
				in.getline(temp, 100);
				
				if(temp[0] == '/' && temp[1] == '/')
				continue;

				if(temp[0] == 10 || temp[0]== 0 || temp[0] == 13) //10 means new line 0 means end of string 13 means "\r"
				continue;

				

				if(!strncmp(temp, "awp", 3))
				cout << (counter+1) << ".\tMagnum Sniper Rifle(awp)\n";

				if(!strncmp(temp, "g3sg1", 5))
				cout << (counter+1) << ".\tD3/AU1\n";

				if(!strncmp(temp, "sg550", 5))
				cout << (counter+1) << ".\tKrieg 550 Commando\n";

				if(!strncmp(temp, "galil", 5))
				cout << (counter+1) << ".\tIDF Defender(galil)\n";

				if(!strncmp(temp, "ak47", 4))
				cout << (counter+1) << ".\tCV-47(AK-47)\n";
				
				if(!strncmp(temp, "scout", 5))
				cout << (counter+1) << ".\tSchmidt Scout\n";

				if(!strncmp(temp, "sg552", 5))
				cout << (counter+1) << ".\tKrieg 552\n";

				if(!strncmp(temp, "famas", 5))
				cout << (counter+1) << ".\tClarion 5.56(famas)\n";

				if(!strncmp(temp, "m4a1", 4))
				cout << (counter+1) << ".\tMaverick M4A1 Carbine(m4a1)\n";	

				if(!strncmp(temp, "aug", 3))
				cout << (counter+1) << ".\tBullpup\n";

				if(!strncmp(temp, "glock", 5))
				cout << (counter+1) << ".\t9x19mm Sidearm(glock)\n";

				if(!strncmp(temp, "usp", 3))
				cout << (counter+1) << ".\tKM .45 Tactical(usp)\n";

				if(!strncmp(temp, "p228", 4))
				cout << (counter+1) << ".\t228 Compact\n";

				if(!strncmp(temp, "deagle", 6))
				cout << (counter+1) << ".\tNight Hawk .50C(deagle)\n";

				if(!strncmp(temp, "elite", 5))
				cout << (counter+1) << ".\t.40 Dual Elites\n";

				if(!strncmp(temp, "fiveseven", 9))
				cout << (counter+1) << ".\tES Five//Seven\n";

				if(!strncmp(temp, "m3", 2))
				cout << (counter+1) << ".\tLeone 12 Gauge Super(m3)\n";

				if(!strncmp(temp, "xm1014", 6))
				cout << (counter+1) << ".\tLeone YG1265 Auto Shotgun\n";

				if(!strncmp(temp, "mac10", 5))
				cout << (counter+1) << ".\tIngram MAC-10\n";

				if(!strncmp(temp, "tmp", 3))
				cout << (counter+1) << ".\tSchmidt Machine Pistol(tmp)\n";

				if(!strncmp(temp, "mp5navy", 7))
				cout << (counter+1) << ".\tKM Sub-Machine Gun(mp5)\n";

				if(!strncmp(temp, "ump45", 5))
				cout << (counter+1) << ".\tKM UMP45\n";

				if(!strncmp(temp, "p90", 3))
				cout << (counter+1) << ".\tES C90\n";

				if(!strncmp(temp, "m249", 4))
				cout << (counter+1) << ".\tM249\n";

				if(!strncmp(temp, "flashbang", 9))
				cout << (counter+1) << ".\tFlashbang\n";

				if(!strncmp(temp, "hegrenade", 9))
				cout << (counter+1) << ".\tHE Grenade\n";

				if(!strncmp(temp, "smokegrenade", 12))
				cout << (counter+1) << ".\tSmoke Grenade\n";

				strncpy(resw[counter], temp, 15);

				counter++;
			}
		}
		else
		cout << "No restricted weapons found. Please add one";


		cout << "\n\n1. Add a weapon\n";
		cout << "2. Delete a waepon\n";
		cout << "3. Delete all\n";
		cout << "4. Exit\n";
		cout << " : ";
		unsigned short int choice;

		cin >> choice;

		switch(choice)
		{
			case 1: 


				


				cout << "\n\nWhich weapon should be restricted?\n\n";

				cout << "1.  Magnum Sniper Rifle(awp)\n";
				cout << "2.  D3/AU1\n";
				cout << "3.  Krieg 550 Commando\n";
				cout << "4.  IDF Defender\n";
				cout << "5.  CV-47(AK -47)\n";
				cout << "6.  Schmidt Scout\n";
				cout << "7.  Krieg 552\n";
				cout << "8.  Clarion 5.56(famas)\n";
				cout << "9.  Maverick M4A1 Carbine(m4a1)\n";
				cout << "10. Bullpup\n";
				cout << "11. 9x19mm Sidearm(glock)\n";
				cout << "12. KM .45 Tactical(usp)\n";
				cout << "13. 228 Compact\n";
				cout << "14. Night Hawk .50C(deagle)\n";
				cout << "15. .40 Dual Elites\n";
				cout << "16. ES Five//Seven\n";
				cout << "17. Leone 12 Gauge Super(m3)\n";
				cout << "18. Leone YG1265 Auto Shotgun\n";
				cout << "19. Ingram MAC-10\n";
				cout << "20. Schmidt Machine Pistol(tmp)\n";
				cout << "21. KM Sub-Machine Gun(mp5)\n";
				cout << "22. KM UMP45\n";
				cout << "23. ES C90\n";
				cout << "24. M249\n";
				cout << "25. Flashbang\n";
				cout << "26. HE Grenade\n";
				cout << "27. Smoke Grenade\n";

				cout << " : ";
				cin >> choice;

				

				{
					ofstream add;
					add.open("server_css/cstrike/cfg/mani_admin_plugin/default_weapon_restrict.txt", ios_base::app);
				
					switch(choice)
					{
						case 1: add << endl << "awp";
							break;
						case 2: add << endl << "g3sg1";
							break;
						case 3: add << endl << "sg550";
							break;
						case 4: add << endl << "galil";
							break;
						case 5: add << endl << "ak47";
							break;
						case 6: add << endl << "scout";
							break;
						case 7: add << endl << "sg552";
							break;
						case 8: add << endl << "famas";
							break;
						case 9: add << endl << "m4a1";
							break;
						case 10: add << endl << "aug";
							break;
						case 11: add << endl << "glock";
							break;
						case 12: add << endl << "usp";
							break;
						case 13: add << endl << "p228";
							break;
						case 14: add << endl << "deagle";
							break;
						case 15: add << endl << "elite";
							break;
						case 16: add << endl << "fiveseven";
							break;
						case 17: add << endl << "m3";
							break;
						case 18: add << endl << "xm1014";
							break;
						case 19: add << endl << "mac10";
							break;
						case 20: add << endl << "tmp";
							break;
						case 21: add << endl << "mp5navy";
							break;
						case 22: add << endl << "ump45";
							break;
						case 23: add << endl << "p90";
							break;
						case 24: add << endl << "m249";
							break;
						case 25: add << endl << "flashbang";
							break;
						case 26: add << endl << "hegrenade";
							break;
						case 27: add << endl << "smokegrenade";
							break;
						default: cout << "\nWrong choice!\n\n";
					}

					add.close();

				}

				break;
			case 2: cout << "\n\nWhich entry do you wish to delete? ";
				cin >> choice;

				choice--;

				if(choice >= counter)
				cout << "\n\nEntry does not exist!\n";

				else
				{
					ofstream out;
					out.open("server_css/cstrike/cfg/mani_admin_plugin/default_weapon_restrict.txt");

					for(int i = 0; i<counter; i++)
					{
						if(i==choice);	//nothing to do
						
						else
						{
							out << resw[i] << endl;
						}
						
					}
					out.close();
				}
				break;
			case 3: char temp;
				cout << "\n\nThe hole voterconlist is going to be deleted. Are you sure?(y|n) ";
				cin >> temp;
				

				if(temp=='y')
				{
					ofstream del_all;
					del_all.open("server_css/cstrike/cfg/mani_admin_plugin/default_weapon_restrict.txt");
					del_all.close();
				}
				break;
			case 4: exit =true;
				break;
			default: cout << "\n\nTry again ;)\n";
		}



	}
}


void mani_voterconlist()
{
	
	char params[200];
	bool exit = false;

	cout << "From which server do you wish to edit the rconlist?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------

	char buf[50][3][50]; //OFF_name means 0, OFF_C menas 1, 2 is the question





	if(installed==true)
	{

	
		strcat(params, "/cfg/mani_admin_plugin/voterconlist.txt");
		


		


		while (!exit)
		{

			unsigned short int counter = 0;

			ifstream in;
			in.open(params);

			if(in.is_open())
			{
			

				cout << "\n\nCurrent voterconlist: \n";


				while(!in.eof())
				{
					char temp[150];
					in.getline(temp, 150);
				
					switch(temp[0])
					{
						case '"': int i;
						  	for(i=1; i<150; i++)
						  	{
								if(temp[i]=='"')
							  	  break;

								buf[counter][OFF_N][(i-1)] = temp[i];
							  }
							  
							  buf[counter][OFF_N][i] = 0; //0 means end of string
							  
							  cout << (counter+1) << ".\t" << buf[counter][OFF_N] << endl;

							  

							  i+=3; //to junp over the '"' and over the ' ' and the second '"'

							  int q;
						  	  for(q=0; i<150; i++, q++)
							  {
								if(temp[i]=='"')
								   break;

								buf[counter][2][q] = temp[i];
							  }

							  i+=2; //to junp over the '"' and over the ' '

							  int j;
						  	  for(j=0; i<150; i++, j++)
							  {
								if((temp[i]=='/' && temp[(i+1)] == '/') || temp[i]==0) //0 means end of string
								   break;

								buf[counter][OFF_C][j] = temp[i];
							  }

							 
							  buf[counter][OFF_C][j] = 0; //0 means end of string
							  buf[counter][2][q] = 0; //0 means end of string

							  //2 is space for the question

							  counter++;
							  
							  temp[0] = 0; //0means end of string, to avoid the bug with the letter when temp[] = "\"\" "
							  
							  break;
			

							
					}
				
				}

				in.close();

			}
		
			else
			cout << "\nYou have no rcon questions, please add one!\n";

		
		

			cout << "\n\n1. Add command\n";
			cout << "2. Delete command\n";
			cout << "3. Edit a command\n";
			cout << "4. Delete hole list\n";
			cout << "5. Exit\n";


			cout << " : ";
			cin >> choice;
			cin.ignore();


			switch(choice)
			{
				case 1: cout << "\nCommand: ";
					{
						char command[50];
						cin.getline(command, 50);

						cout << "\nName: ";
						char name[50];
						cin.getline(name, 50);

						cout << "\nQuestion: ";
						char question[100];
						cin.getline(question, 100);

						ofstream out;
						out.open(params, ios_base::app);
						out << endl << "\"" << name << "\"" << " \"" << question << "\" " << command;
						out.close();
					}
					break;

			
				case 2: cout << "\n\nWhich entry do you want do delete? ";
					cin >> choice;
		
					choice--;

					if(choice >= counter)
					{
						cout << "\nThis entry does not exist!\n\n";
					}
					else
					{

						ofstream save_del;
						save_del.open(params);




						for (int i = 0;i<counter;i++)
						{

						
							if(i==choice)
							{
								//nothing to do
							}
							else
							{
								save_del << endl << "\"" << buf[i][OFF_N] << "\"" << " \"" << buf[i][2] << "\" " << buf[i][OFF_C];

								//2 is space for the question
							}
							
						}
						save_del.close();
					}
					break;


				case 3:	cout << "\nWhich entry do you wish do edit? ";
					cin >> choice;
					
					choice--; //for the right arry


					if (choice >= counter)
					{
						cout << "\n\nThis entry does not exist!\n\n";
					}
					else
					{
						cout << "\n\n1. Edit the Name\n";
						cout << "2. Edit the command\n";
						cout << "3. Edit the question\n";
						cout << " : ";
						unsigned short int temp_e;
						cin >> temp_e;

						

						if(temp_e > 3)
						{
							cout << "\n\nWrong choice!\n";
						}
						else
						{

							temp_e--;  //for the right array
							cout << "\nNew name/command/question: ";
							cin.getline(buf[choice][temp_e], 100);

	

							ofstream save_edit;
							save_edit.open(params);




							for (int i = 0;i<counter;i++)
							    save_edit << "\"" << buf[i][OFF_N] << "\"" << " \"" << buf[i][2] << "\" " << buf[i][OFF_C] << endl;

				
						
						}

					}

					break;

				case 4: char temp;
					cout << "\n\nThe hole voterconlist is going to be deleted. Are you sure?(y|n) ";
					cin >> temp;
					

					if(temp=='y')
					{
						ofstream del_all;
						del_all.open(params);
						del_all.close();
					}
					break;
				case 5: exit = true;
					break;
				default: cout << "\n\nTry again;)\n";
			}
		}
	}
}

void edit_manicfg()
{
	cout << "\n\nFrom which server do you wish to edit the mani_server.cfg?\n";

	is_installed();

	unsigned short int choice;
	cout << "\n : ";
	cin >> choice;
	
	char params[100];

	//if it is really installed	
	installed = false;
	mani_test(choice);
	strcpy(params, param);
	//-------end---------
	
	strcat(params, "/cfg/mani_server.cfg");
	
	
	cout << "\n\nWhich editor do you wish to edit the mani_server.cfg\n";
	cout << "1. Nano\n";
	cout << "2. Vim\n";
	cout << "3. Specify Editor\n";
	cout << " : ";
	
	cin >> choice;
	cin.ignore();
	
	switch (choice)
	{
		case 1: strcpy(param, "nano ");
			strcat(param, params);
			system(param);
			//using param because it is more efficent
			break;
		case 2: strcpy(param, "vim ");
			strcat(param, params);
			system(param);
			//using param because it is more efficent
			break;
		case 3: cout << "Command for the editor you want to use?(eg. nano, vim, kate, kwrite, gedit) ";
			char temp[20];
			cin.getline(temp, 20);
			strcpy(param, temp);
			strcat(param, " ");
			strcat(param, params);
			system(param);
			//using param because it is more efficent
			break;
		default: cout << "\n\nWrong choice!\n\n";
			break;
	}
}



void config_mani()
{

	bool exit = false;

	while(!exit)
	{
		cout << "\n\n1.  Install mani admin plugin\n";
		cout << "2.  Deactivate mani admin plugin\n";
		cout << "3.  Configurate Admins\n";
		cout << "4.  Configurate votemapslist\n";
		cout << "5.  Configurate wordfilter\n";
		cout << "6.  Configurate rconlist\n";
		cout << "7.  Configurate votequestionlist\n";
		cout << "8.  Configurate reserveslots\n";
		cout << "9.  Configurate pingimmunities\n";
		cout << "10. Configurate restricted weapons\n";
		cout << "11. Configurate voterconlist\n";
		cout << "12. Edit mani_server.cfg (main config for mani admin plugin)\n";
		cout << "13. Exit\n";
		cout << " : ";

		unsigned short int choice;
		cin >> choice;
		cin.ignore();

		switch (choice)
		{
			case 1: install_mani();
				break;
			case 2:	deactivate_mani();
				break;
			case 3: mani_admins();
				break;
			case 4: edit_mapcl(3); //3 means votemaplist.txt
				break;
			case 5: mani_wordfilter();
				break;
			case 6: mani_rcon();
				break;
			case 7: mani_votequestionlist();
				break;
			case 8: mani_ping_reserve(1); //1 means reserveslots
				break;
			case 9: mani_ping_reserve(2); //2 means pingimmunity
				break;
			case 10: mani_resw();
				 break;
			case 11: mani_voterconlist();
				 break;
			case 12: edit_manicfg();
				 break;
			case 13: exit = true;
				break;
			default: cout << "\n\nTry again;)\n";
		}
	}
}


//here you can Configurate servers
void config_server()
{
	bool exit=false;

	while(!exit)
	{
		unsigned short int choice;
		cout << "\n\n1. Copy maps into server\n";
		cout << "2. Edit maplist\n";
		cout << "3. Edit mapcylce\n";
		cout << "4. Configure mani admin plugin\n";
		cout << "5. Exit to main menu\n";
		cout << " : ";
		cin  >> choice;	

		switch(choice)
		{
			case 1: copy_maps();
				break;
			case 2: edit_mapcl(1); //1 means edit maplist.txt
				break;
			case 3: edit_mapcl(2); //2 means edit mapcycle.txt
				break;
			case 4:	config_mani();
				break;
			case 5: exit=true;
				break;
			default: cout << "\n\nWrong choice. Try again;)";
				 break;
		}
	}
}


//here you can update the server with verifying all data!
void update_server()
{
	
	cout << "\n\nWhich server do you wish to update?\n\n";
	
	is_installed();
	
	

	unsigned short int choice;
	cout << " : ";
	cin >> choice;
	cin.ignore();

	switch(choice)
	{
		case 1:	if(server_css==true)
				{
					cout << "\n\nUpdating Counter Strike-Source...";
					system("./steam -command update -game \"Counter-Strike Source\" -dir server_css -verify_all");
				}
				else
				not_installed();
				break;
		case 2:	if(server_dods==true)
				{
					cout << "\n\nUpdating Day of Defeat Source...";
					system("./steam -command update -game \"dods\" -dir server_dods -verify_all");
				}
				else
				not_installed();
				break;

		case 5:	if(server_hl2mp==true)
				{
					cout << "\n\nUpdating Half Life 2 Death Match...";
					system("./steam -command update -game \"hl2mp\" -dir server_hl2mp -verify_all");
				}
				else
				not_installed();
				break;
		case 6:	if(server_tf==true)
				{
					cout << "\n\nUpdating Team Fortress...";
					system("./steam -command update -game \"tf\" -dir server_tf -verify_all");
				}
				else
				not_installed();
				break;
		case 7:	if(server_cs==true)
				{
					cout << "\n\nUpdating Counter Strike...";
					system("./steam -command update -game \"cs\" -dir server_cs -verify_all");
				}
				else
				not_installed();
				break;
		case 8:	if(server_czero==true)
				{
					cout << "\n\nUpdating Counter Strike Condition Zero...";
					system("./steam -command update -game \"czero\" -dir server_czero -verify_all");
				}
				else
				not_installed();
				break;
		case 9:	if(server_dmc==true)
				{
					cout << "\n\nUpdating Death Match Classic...";
					system("./steam -command update -game \"dmc\" -dir server_dmc -verify_all");
				}
				else
				not_installed();
				break;
		case 10:	if(server_dod==true)
				{
					cout << "\n\nUpdating Day of Defeat...";
					system("./steam -command update -game \"dod\" -dir server_dod -verify_all");
				}
				else
				not_installed();
				break;
		case 11:	if(server_gearbox==true)
				{
					cout << "\n\nUpdating Opposing Force...";
					system("./steam -command update -game \"gearbox\" -dir server_gearbox -verify_all");
				}
				else
				not_installed();
				break;
		case 12:	if(server_ricochet==true)
				{
					cout << "\n\nUpdating ricochet...";
					system("./steam -command update -game \"ricochet\" -dir server_ricochet -verify_all");
				}
				else
				not_installed();
				break;
		case 13:	if(server_tfc==true)
				{
					cout << "\n\nUpdating Team Fortress Classic...";
					system("./steam -command update -game \"tfc\" -dir server_tfc -verify_all");
				}
				else
				not_installed();
				break;
		case 14:	if(server_darkmessiah==true)
				{
					cout << "\n\nUpdating Dark Messiah...";
					system("./steam -command update -game \"darkmessiah\" -dir server_darkmessiah -verify_all");
				}
				else
				not_installed();
				break;
		default: cout << "\n\nTry again ;)\n\n";
				break;
	}

	


}


//to update the client
void update_client()
{
	cout << "Updating Steam Linux Client\n\n";
	system("./steam -command update");

	cout << "\n\nUpdated\n\n";
}


//main menu
int main(int argc, char *argv[]) //the parameters aren't needed yet
{
	system("clear;clear;clear"); //for a better look ;)
	
	char choice;

	cout << "steamserverutil v 0.2.4.3 by MJ, hanfman_cool@web.de\n\n" << endl;
	
	

	ifstream test_file;
	test_file.open("hldsupdatetool.bin");

	if(test_file.is_open())
	{
		cout << "found hldsupdatetool.bin\n";
	}
	else
	{
		cout << "downloading hldsupdatetool.bin with wget\n\n";
		system("wget http://www.steampowered.com/download/hldsupdatetool.bin");
		system("chmod +x hldsupdatetool.bin");
	}
	test_file.close();



	
	test_file.open("steam");
	
	if( !test_file.is_open() )
	{
		cout << "\n\nFirst you have to accept the license agreement, show now?(y|n) ";
		cin >> choice;

		cout << "\n\n";
	
		if (choice == 'y')
		{
			system("./hldsupdatetool.bin");
		}
		else
		{
			cout << "Aborting...\n";
			return 0;
		}	
			
	}
	
	

	test_file.close();
	test_file.open("steam");

	if( test_file.is_open())
	{
		cout << "\nfound steam\n\n";

		test_file.close();
		
		
		bool exit=false;

		
		while(!exit)
		{
			unsigned int menu;
			cout << "\n\n\t**main menu**\n";
			cout << "1. Install or update game server\n";
			cout << "2. Start game server\n";
			cout << "3. Favorites\n";
			cout << "4. Configurate servers\n";
			cout << "5. Update game servers (verifys all data!)\n";
			cout << "6. Update Steam Linux Client (recommend for first use)\n";
			cout << "7. Exit\n";
			cout << " : ";
			cin >> menu;
			
			cin.ignore();

			switch (menu)
			{
				case 1: 	install();
						break;
				case 2: 	start();
						break;
				case 3: 	favorites();
						break;
				case 4:		config_server();
						break;
				case 5:		update_server();
						break;
				case 6:		update_client();
						break;
				case 7: 	exit=true;
						break;
				default:	cout << "Try again ;)";
						break;
			}

		}
	}
	else
	{
		never_happen();
		cout << "\nUnknown Error!\n";
		return 0;
	}


	return 1;
}
